<template>
    <div>
        <el-card>
            <el-row>
                <el-col :span="8">
                    <el-input v-model="queryInfo.query" clearable @clear="getOrderList">
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <el-table :data="orderList" border stripe>
                <el-table-column type="index"></el-table-column>
                <el-table-column prop="order_number" label="订单编号"></el-table-column>
                <el-table-column prop="order_price" label="订单价格"></el-table-column>
                <el-table-column label="是否付款">
                    <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.pay_status==='1'">已付款</el-tag>
                        <el-tag type="danger" v-else>未付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货"></el-table-column>
                <el-table-column prop="create_time" label="下单时间">
                    <template slot-scope="scope">
                        {{scope.create_time | dateFormat}}
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" size="mini" @click="showBox"></el-button>
                        <el-button type="success" icon="el-icon-location" size="mini"
                                   @click="showProgressBox"></el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
        <el-dialog
                @close="addressDialogClose"
                title="修改地址"
                :visible.sync="dialogVisible"
                width="50%">
            <el-form :model="addressFrom" :rules="addressFormRules" ref="addressFormRef" label-width="100px"
                     class="demo-ruleForm">
                <el-form-item label="省市区/县" prop="address1">
                    <el-cascader :options="cityData" v-model="addressFrom.address1"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="addressFrom.address2"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog
                title="物流进度"
                :visible.sync="dialogVisible1"
                width="50%">
            <el-timeline :reverse="reverse">
                <el-timeline-item
                        v-for="(activity, index) in activities"
                        :key="index"
                        :timestamp="activity.time">
                    {{activity.context}}
                </el-timeline-item>
            </el-timeline>
        </el-dialog>
    </div>
</template>

<script>
    import Pager from '../Pager'
    import cityData from './citydata'

    export default {
        data() {
            return {
                dialogVisible1:false,
                dialogVisible: false,
                activities:[],
                queryInfo: {
                    query: '',
                    pagenum: 1,
                    pagesize: 10
                },
                total: 0,
                orderList: [],
                addressFrom: {
                    address1: [],
                    address2: ""
                },
                addressFormRules: {
                    address1: [
                        {required: true, message: '请输入省市区/县', trigger: 'blur'}
                    ],
                    address2: [
                        {required: true, message: '详细地址', trigger: 'blur'}
                    ]
                },
                cityData,
            }

        },
        created() {
            this.getOrderList()
        },
        methods: {
            async showProgressBox() {
                const {data: res} = await this.$http.get('/kuaidi/1106975712662');
                this.dialogVisible1=true
                if (res.meta.status !== 200) {
                    this.$message.error("获取失败")
                } else {
                    this.activities=res.data
                }

            },
            addressDialogClose() {
                this.$refs.addressFormRef.resetFields()
            },
            //监听pagesize改变事件
            handleSizeChange(val) {
                this.queryInfo.pagesize = val;
                this.getOrderList();
            },
            //监听页码值改变的事件
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.queryInfo.pagenum = val;
                this.getOrderList();
            },
            async getOrderList() {
                const {data: res} = await this.$http.get('orders', {params: this.queryInfo});
                if (res.meta.status !== 200) {
                    this.$message.error("获取失败")
                } else {
                    this.orderList = res.data.goods
                    this.total = res.data.total
                }
            },
            showBox() {
                this.dialogVisible = true
            }
        },
        components: {
            Pager
        },
    }
</script>

<style lang="less" scoped>
    .el-cascader {
        width: 100%;
    }
</style>